#pragma strict

var minSpeed:float;
var maxSpeed:float;
var life:float;
var hurt:float;
var explotionPrefab:GameObject;
var projectGameObject:Transform;
var interval:float;
private var myTransform:Transform;
private var x;
private var y=6.5f;
private var z=0f;
function Start () {
	myTransform=this.transform;
	x=Random.Range(7f,-7f);
	myTransform.position=Vector3(x,y,z);
	StartCoroutine(Fire());
}

function Update () {
	
	var amtMove=Random.Range(minSpeed,maxSpeed)*Time.deltaTime;
	myTransform.Translate(Vector3.left*-amtMove);
	if(myTransform.position.y<=-4.5f)
	{
		Destroy(this.gameObject);
	}
}

//发生碰撞后减血
function OnTriggerEnter (other:Collider ) {
	//如果碰撞体为炮弹
	if(other.GetComponent(Projectile)){
		var paodan:Projectile;
		paodan=other.GetComponent(Projectile);
		life-=paodan.hurt;
		if(life<=0)//生命值小于0--死了
		{
			doparticleSystem();
			AutoEnemy.integral+=5;
			Destroy(this.gameObject);
		}
	}
	if(other.GetComponent(jsPlayer)){
		doparticleSystem();
		Destroy(this.gameObject);
	}
}

function Fire()
{
	while (true) {
		yield WaitForSeconds(interval);
		//Debug.Log("shua");
		Instantiate(projectGameObject,Vector3(this.transform.position.x,this.transform.position.y-this.transform.rotation.y+this.transform.position.z),Quaternion.identity);
	}
}

//爆炸
function doparticleSystem()
{
	Instantiate(explotionPrefab,this.transform.position,this.transform.rotation);
}

